<template>
    <div>
    <h1>科室修改页面</h1>
            <table class="table">
                <thead>
                    <tr>
                        <td>科室名称:</td>
                        <td><input type="text" v-model="data.keName"></td>
                    </tr>
                    <tr>
                        <td>科室人数:</td>
                        <td><input type="text" v-model="data.kePeople"></td>
                    </tr>
                    <tr>
                        <td>科室描述:</td>
                        <td><input type="text" v-model="data.keMiaoS"></td>
                    </tr>
                    <tr>
                        <td>创建日期:</td>
                        <td><input type="date" v-model="data.keTimes"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="button" value="修改" @click="Add" class="btn btn-success"></td>
                    </tr>
                </thead>
            </table>
    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute();
const router = useRouter();
onMounted(()=>{
    Show()
})

const Show=()=>{
    axios.get("/api/KeHome/GetKeHome",{params:{id:route.query.id}}).then(res=>{
           data.value=res.data;
           data.value.keTimes=data.value.keTimes.substring(0,10);
    })
}







const data = ref({
    "kid": 0,
  "keName": "",
  "kePeople": "",
  "keMiaoS": "",
  "keTimes": "2025-05-19T02:54:15.497Z",
  "keLuoji": true
});

const Add=()=>{
    axios.post("/api/KeHome/UpdateKeHome",data.value).then(res=>{
                if(res.data==-1)
            {
                alert("科室名称已存在!");
                return;
            }
            if(res.data>0)
            {
                    alert("修改成功!");
                    router.push({path:'/KeHomeShow'})
            }
            else{
                alert("修改失败!");
                return;
            }
           
    })
}




</script>

<style scoped>

</style>